<template>
	<div class="box" style="background: #fff;padding: 0;">
		<div class="seach">
			<input type="text" placeholder="请输入法律名称" v-model="seachObj.iawName" @input="getInit()" />
		</div>

		<ul class="list">
			<li v-for="item,index in lawList" :key="index" @click="goDetail($event , item)">
				<div style="display: flex;justify-content: space-between;">
					<h3>《{{item.iawName}}》</h3>
					<van-icon name="edit" id="edit" color='#e53935' />
				</div>
				<div class="hr"></div>
				<p>创建时间：{{item.createTime}}</p>
				<p>条款数量：{{item.length || '0'}}条</p>
				<p>法律介绍：{{item.iawIntroduce || '--'}}</p>
			</li>
		</ul>

		<div class="btn">
			<button @click="addLaw">新增法规</button>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				seachObj: {},
				lawList: []
			}
		},

		onShow() {
			this.getInit()
		},

		methods: {
			async getInit() {
				let result = await this.$axios('overallSituation', {
					databaseName: 'lawList',
					state: 'look',
					...this.seachObj
				}, true)

				if (result.code == 200) {
					this.lawList = result.data
				}
			},

			// 点击前往法律详情页面
			goDetail(e, item) {
				if(e.target.id == 'edit'){
					this.edit(item)
				}else {
					this.$router(`/subPackages2/pages/law/detail?_id=${item._id}`)
				}
			},
			
			// 修改
			edit(item) {
				this.$router(`/subPackages2/pages/law/add?_id=${item._id}`)
			},
			
			// 添加
			addLaw() {
				this.$router('/subPackages2/pages/law/add')
			}
		}
	}
</script>

<style scoped>
	.seach {
		width: 100%;
		height: 7vh;
		margin-bottom: 10px;
		padding: 10px;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: -1px 0 5px 0 rgba(0, 0, 0, 0.4);
	}

	.seach input {
		width: 98%;
		height: 35px;
		border-radius: 10px;
		border: 1px solid #e53935;
		padding: 0 10px;
		box-sizing: border-box;
		font-size: 12px;
		color: #333;
	}

	.list {
		width: 100%;
		height: 84%;
		display: flex;
		align-items: center;
		flex-direction: column;
		overflow-y: scroll;
	}

	.list li {
		width: 95%;
		padding: 10px;
		border-radius: 10px;
		box-sizing: border-box;
		border: 1px solid #e53935;
		border-left: 3px solid red;
		border-right: 3px solid red;
		margin-bottom: 15px;
	}

	.list li h3 {
		font-size: 14px;
		font-weight: 700;
	}

	.list li .hr {
		width: 100%;
		height: 1px;
		background: #ef5350;
		margin: 5px 0;
	}

	.list li p {
		font-size: 12px;
		color: #333;
		margin: 5px 0;
	}

	.btn {
		width: 100%;
		height: 7vh;
		padding: 10px;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 1px 0 5px 0 rgba(0, 0, 0, 0.4);
		position: fixed;
		bottom: 0;
		left: 0;
	}

	.btn button {
		width: 100%;
		height: 35px;
		background: #e53935;
		color: #fff;
		font-size: 12px;
		font-weight: 700;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>